package com.dxd.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.xml.DOMConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Log4jServlet extends HttpServlet {

	private static final long serialVersionUID = 2033209495608146519L;
	private static final Logger log = LoggerFactory.getLogger(Log4jServlet.class);

	public Log4jServlet() {
	}

	public void init() throws ServletException {
		log.info(" Initializing, My MyActionServlet init this System's Const Variable ");
		String prefix = this.getServletConfig().getServletContext().getRealPath("/"); // 读取项目的路径
		String file = this.getServletConfig().getInitParameter("log4j"); // 读取log4j相对路径
		String filePath = prefix + file;
		System.out.println(filePath);
		DOMConfigurator.configure(filePath); // 加载.xml文件
		log.info(" Initializing, end My Init ");
		super.init(); // 此方法不能省，ActionServlet覆盖了的此方法中有很多重要操作
	}
}